package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyContent;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.mapper.StrategyContentMapper;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    private StrategyMapper strategyMapper;
    @Autowired
    private StrategyContentMapper contentMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        //排序
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId()!=null){
            //修改
            strategyMapper.updateByPrimaryKey(strategy);
        }else {
            //保存
            strategyMapper.insert(strategy);
        }
    }

    @Override
    public List<Strategy> list() {
        return strategyMapper.selectAll();
    }

    @Override
    public StrategyContent getContentByStrategyDetailId(Long detailId) {
        return contentMapper.selectContentByStrategyDetailId(detailId);
    }

    @Override
    public List<Strategy> getStrategies(StrategyQuery qo) {
        return strategyMapper.selectForList(qo);
    }

    @Override
    public Strategy get(Long strategyId) {
        return strategyMapper.selectByPrimaryKey(strategyId);
    }

    @Override
    public PageInfo selectStrategysByuserId(StrategyQuery qo, Long id) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.selectStrategysByuserId(id);
        return new PageInfo(list);
    }

    @Override
    public Strategy getStrategy(Long id) {
        return strategyMapper.selectByPrimaryKey(id) ;
    }


}
